//定义表示记分牌的类
class ScorePanel{
    //分数
    score = 0;
    //等级
    level = 1;
    //分数和等级所有的元素，在构造函数中进行初始化
    scoreEle:HTMLElement;
    levelEle:HTMLElement;
    //设置一个变量限制等级
    maxLevel:number;
    //设置一个变量表示多少分升级
    upScore:number;
    constructor(maxLevel:number = 10,upScore:number = 10){
        this.maxLevel = maxLevel;
        this.upScore = upScore;
        this.scoreEle = document.getElementById('score')!
        this.levelEle = document.getElementById('level')!
    }

    //设置加分方法
    addScore(){
        //使分数自增
        this.scoreEle.innerHTML = ++this.score + '';
        //判断分数是多少
        if(this.score % this.upScore === 0)
            this.levelUp();
    }

    //提升等级的方法
    levelUp(){
        if(this.level < this.maxLevel) 
            this.levelEle.innerHTML = ++this.level + '';
    }
}

export default ScorePanel;